Integration test: API facts endpoints (FastAPI TestClient + Redis)#2411
Conversation
The integration tests drive the FastAPI app through fastapi.testclient.TestClient, which requires httpx as its transport. Add it to [dev-packages] and re-lock so that pipenv install --dev --deploy keeps verifying the lock in CI. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Christian Berendt <berendt@osism.tech>
Drive the read-only GET /v1/inventory/hosts/{host}/facts and
.../facts/{fact} endpoints through fastapi.testclient.TestClient
against the live Redis. The endpoints read the ansible_facts<host>
cache key directly, so each test seeds that exact key and removes it
in teardown.
Coverage: parsed facts with the correct count, a single fact value,
404 for an unknown fact, 404 for an unknown host on both endpoints,
and 500 for malformed JSON in the cache.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Christian Berendt <berendt@osism.tech>
Rebase analysis: #2411
e5e890c Add httpx to dev dependencies for FastAPI TestClientNo adjustments needed — the upstream range does not invalidate this commit. 1845401 Add integration tests for inventory facts API endpointsNo adjustments needed — the upstream range does not invalidate this commit. SummaryThe rebase landed cleanly. The httpx commit (e5e890c) shares Pipfile/Pipfile.lock with the upstream paramiko v5 bump (4ff2168), but its pre-image Pipfile blob (b1dbd4e) is byte-identical to the post-paramiko Pipfile, so the lock _meta hash (feebbac3) is consistent with paramiko==5.0.0 + httpx==0.28.1 and pipenv --deploy verification still passes. The integration-tests commit (1845401) depends only on osism.utils.redis, osism.api.app, the unchanged facts endpoints (api.py:932/971), and the integration conftest — none of which the upstream localhost-exclusion change (5b34431, scoped to check_ansible_facts()) or the paramiko bump touches. Important Recommendation: Safe to push as-is. Neither upstream commit invalidates any assumption in the two rebased commits; no adjustments are required. Rebase analysis generated by planwerk-review c7d1c16 rebase with Claude |
cc41349 to
1845401
Compare
What
Integration coverage for the read-only inventory-facts HTTP endpoints, which
read straight from Redis:
GET /v1/inventory/hosts/{host}/facts(osism/api.py:927)GET /v1/inventory/hosts/{host}/facts/{fact}(osism/api.py:966)Both call
utils.redis.get("ansible_facts{host}"). Driving them throughfastapi.testclient.TestClientagainst the live Redis exercises the API↔Redisread path end-to-end. The suite is skipped automatically when Redis is not
reachable, like the other modules under
tests/integration/.Part of #2400. Follow-up to #2368.
Changes (in commit order)
Add httpx to dev dependencies for FastAPI TestClient —
fastapi.testclient.TestClientneeds
httpxas its transport. Addshttpx = "==0.28.1"to[dev-packages]and regenerates
Pipfile.locksopipenv install --dev --deploykeepsverifying the lock in CI. The lock diff adds only
httpxand its transitives(
httpcore,h11,anyio,sniffio,idna,certifi,typing-extensions)to
develop; no runtime pins move.Add integration tests for inventory facts API endpoints — new module
tests/integration/test_api_facts.py. Each test seeds the exactansible_facts<host>key (UUID-based host) and deletes it in teardown.Covers every Scope item from the issue:
countandfrom_cacheflag;Notes
osism.apiwires the event bridge to Redis at import time, so theimport is deferred into the
clientfixture — fine in the integration envwhere Redis is up (and the suite is skipped without it).
Meta: Extend Celery/Redis integration tests (Tier 1 + Tier 2) #2400 siblings; it is intentionally left untouched here to avoid per-issue
merge churn. The existing warning block already covers the per-run UUID keys.
Test plan
tests/integrationwith a live Redis (playbooks/test-integration.yml,OSISM_REQUIRE_REDIS=1). Per repo convention the tests run in CI, not locally.pipenv verify(lock in sync) andflake8on the new file.Closes #2406
Implemented by planwerk-review f1c04d7 with Claude:claude-opus-4-8